<template>
	<form-container
		:title="formData.id ? '编辑检验方案信息' : '新增检验方案信息'"
		:width="550"
		:visible="visible"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="名称：" name="name">
				<a-input v-model:value="formData.name" placeholder="请输入名称" allow-clear />
			</a-form-item>
			<a-form-item label="类型：" name="type">
				<a-select v-model:value="formData.type" placeholder="请选择分类" :options="TypeOptions" allow-clear></a-select>
			</a-form-item>
			<a-form-item label="检验方式：" name="manner">
				<a-select v-model:value="formData.manner" placeholder="请选择分类" :options="MedthOptions" allow-clear></a-select>
			</a-form-item>
			<a-form-item label="值：" name="value">
				<a-input v-model:value="formData.value" placeholder="请输入备注" allow-clear />
			</a-form-item>
			<a-form-item label="描述：" name="desc">
				<a-input v-model:value="formData.desc" placeholder="请输入备注" allow-clear />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-checkbox class="mr-2" v-if="!formData.id" v-model:checked="addNext">继续新增下一条</a-checkbox>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
		</template>
	</form-container>
</template>

<script setup name="ProcessRouteForm">
import { required } from '@/utils/formRules'
import { getCurrentInstance, ref } from 'vue'
import tool from '@/utils/tool'
import protocol from '@/api/mes/basicdata/protocol'
import { message } from 'ant-design-vue'
import { UploadOutlined } from '@ant-design/icons-vue'
import axios from 'axios'

	// 默认是关闭状态
	let visible = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	
	// 继续新增下一条
    const addNext = ref(false)

    //类型
    const TypeOptions = tool.dictList('PROTOCOL')
	//方式
    const MedthOptions = tool.dictList('INSMTHOD')

	// 打开抽屉
	const onOpen = () => {
		visible.value = true
		formData.value = {}
	}
	// 关闭抽屉
	const onClose = () => {
		emit('successful')
		visible.value = false
	}


	// 验证并提交数据
	const onSubmit = () => {
		formRef.value.validate().then(() => {
			protocol.protocolAdd(formData.value).then(() => {
				if (addNext.value) {
					formData.value = {
						sortCode: 99
					}
				} else {
					onClose()
				}
				emit('successful')
			})
		})
	}


	// 调用这个函数将子组件的一些数据和方法暴露出去
	defineExpose({
		onOpen
	})

</script>
